package org.thss.petri.gef.commands;

import org.eclipse.gef.commands.Command;
import org.thss.petri.model.Place;
import org.thss.petri.model.Token;

public class DeleteTokenCommand extends Command {
	private Place container;
	private Token token;
	
	public Token getToken() {
		return token;
	}
	
	public void setToken(Token token) {
		this.token = token;
		if (token != null) {
			this.container = token.getPlace();
		}
	}

	@Override
	public boolean canExecute() {
		return token != null && container != null;
	}

	@Override
	public void execute() {
		container.getTokens().remove(token);
		token.setPlace(null);
	}

	@Override
	public void redo() {
		execute();
	}

	@Override
	public void undo() {
		token.setPlace(container);
		container.getTokens().add(token);
	}

}
